/*
 * BattlePetResource.h
 *
 *  Created on: 2013. 9. 12.
 *      Author: mega@gamevil.com
 */

#ifndef BATTLEPETGACHYARESOURCE_H_
#define BATTLEPETGACHYARESOURCE_H_

#define BATTLE_PET_RANGE_MIN	8	// 전투펫 속성값 계산을 위한 범위 최소값
#define BATTLE_PET_RANGE_MAX	11	// 전투펫 속성값 계산을 위한 범위 최대값

#include <map>
#include "../NLogic/Item.h"

namespace ProjectZ { namespace NResource {

class BattlePetGachyaData
{
public:
	struct Key
	{
		Key() : type(0), sub_type(0) {}
		Key(int rType, int rSubType) : type(rType), sub_type(rSubType) {}

		int type;
		int sub_type;

		bool operator == (const Key & rSide) const
		{
			if (this->type == rSide.type && this->sub_type == rSide.sub_type)
				return true;

			return false;
		}

		bool operator < (const Key & rSide) const
		{
			if (this->type < rSide.type)
			{
				return true;
			}
			else if (this->type == rSide.type)
			{
				if (this->sub_type < rSide.sub_type)
					return true;
			}

			return false;
		}
	};

public:
	struct Flyweight
	{
		int _TYPE;
		int _SUB_TYPE;
		int _VALUE1;
		int _VALUE2;
		int _VALUE3;
	};

public:
	typedef std::map<Key, Flyweight *> BATTLEPETTREE;

public:
	BattlePetGachyaData() {}
	virtual ~BattlePetGachyaData();

	bool LoadResource(int company, int saleCode);
	Flyweight * GetFly(Key & clsKey);

	BATTLEPETTREE & GetTree() { return clsFlyTree; }

private:
	void	Clear();

private:
	BATTLEPETTREE clsFlyTree;
};





class BattlePetGachyaResource
{
public:
	enum BattlePetGachyaType
	{
		EM_BATTLEPET_GACHYA_LEVEL_RATE		= 1,			// 레벨 결정 확률
		EM_BATTLEPET_GACHYA_QUALITY_RATE,					// 등급 결정 확률
		EM_BATTLEPET_GACHYA_ATTR_TYPE_RATE,					// 속성 결정 확률
		EM_BATTLEPET_GACHYA_BATTLE_TYPE_RATE,				// 전투타입 결정 확률
		EM_BATTLEPET_GACHYA_ATTR_WEIGHT_CONST,				// 속성값 가중치
		EM_BATTLEPET_GACHYA_ABLITY_WEIGHT_CONST,			// 능력치 가중치
		EM_BATTLEPET_GACHYA_DGREE_RATE,						// 차수 결정 확률
		EM_BATTLEPET_GACHYA_COMBINE_RATE,					// 합성 확률

		EM_BATTLEPET_GACHYA_LEVEL_RATE_EVENT		= 9,		// 이벤트_레벨 결정 확률
		EM_BATTLEPET_GACHYA_QUALITY_RATE_EVENT,					// 이벤트_등급 결정 확률
		EM_BATTLEPET_GACHYA_ATTR_TYPE_RATE_EVENT,				// 이벤트_속성 결정 확률
		EM_BATTLEPET_GACHYA_BATTLE_TYPE_RATE_EVENT,				// 이벤트_전투타입 결정 확률
		EM_BATTLEPET_GACHYA_ATTR_WEIGHT_CONST_EVENT,			// 이벤트_속성값 가중치
		EM_BATTLEPET_GACHYA_ABLITY_WEIGHT_CONST_EVENT,			// 이벤트_능력치 가중치
	};

public:
	BattlePetGachyaResource();
	virtual ~BattlePetGachyaResource();

	bool LoadResource();

	BattlePetGachyaData::Flyweight * GetFly(int company, int saleCode, BattlePetGachyaData::Key & clsKey);

	void		AddBattlePetHP(User * pUser, int petType, int & hp);
	bool		BattlePetGachya(User * pUser, NLogic::Item::Data & clsData, int excludeType, int gachyaQuality);
	int			BattlePetCombine(User * pUser, NLogic::Item::Data & clsDataBase , NLogic::Item::Data & clsDataMaterial, int combineType);
	int			BattlePetEvolution(User * pUser, NLogic::Item::Data & clsDataBase, NLogic::Item::Data & clsDataMaterial, int materialCount, NLogic::Item::Data & clsDataMaterial2, int materialCount2);
	int			BattlePetEvolutionV2(User * pUser, NLogic::Item * pItem);

	void		BattlePetGachyaForTEST(User * pUser, int level, int quality);

	bool		SetBaseBattlePetInfo(User * pUser, NLogic::Item::Data & clsData, int excludeType, int gachyaQuality);

private:
	BattlePetGachyaData *	GetDataPtr(User * pUser);
	bool		IsBattlePetGachyaEvent(User * pUser);
	int			GetBattlePetLevel(BattlePetGachyaData * pPet, bool bEvent);
	int			GetBattlePetQuality(BattlePetGachyaData * pPet, bool bEvent, int gachyaQuality);
	int			GetBattlePetAttrType(BattlePetGachyaData * pPet, bool bEvent, int excludeType);
	int			GetBattlePetBattleType(BattlePetGachyaData * pPet, bool bEvent);
	bool		GetBattlePetAttrValue(BattlePetGachyaData * pPet, bool bEvent, NLogic::Item::Data & clsData, int attrType);
	bool		GetBattlePetKind(BattlePetGachyaData * pPet, NLogic::Item::Data & clsData, int level);


private:
	BattlePetGachyaData * pBattlepetAD;
	BattlePetGachyaData * pBattlepetIOS;
};

} /* NResource */ } /* ProjectZ */


#endif /* BATTLEPETREGACHYASOURCE_H_ */
